package com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.service.order;

import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.mode.factory.UserVipServiceFactory;
import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.mode.product.IUserVipService;
import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @description:
 * @date: 2022/11/13 18:16.
 * @version: 1.0
 */
@Slf4j
@Service
public class OrderServiceImpl implements IOrderService {

    @Override
    public String buyCourse(User user, Long courseId) {

        // 根据不同身份匹配不同的身份对象信息
        IUserVipService userVipService = UserVipServiceFactory.getInstance(user.getVip());
        // 而后根据身份信息调用自身的行为
        Double coursePrice = userVipService.getMoney(100d);
        Integer cron = userVipService.getCron();

        log.info("用户{}，身份是{}，购买了课程:{}，价格是：{}，获得的学习币：{}", user.getUsername(), user.getVip(), courseId, coursePrice, cron);

        return "success";
    }

}
